﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Budgeter.Models;
using Budgeter.Extensions;

namespace Budgeter.DummyData
{
    public class DummyBudgetGenerator
    {

        public static void MaybePopulate(BudgeterContext context)
        {
            if (!HasBeenPopulated(context))
                Populate(context);
        }

        public static bool HasBeenPopulated(BudgeterContext context)
        {
            return context.Budgets.Any(x => x.ReceiptNumber == 111111);
        }

        public static void Populate(BudgeterContext context)
        {
            var budgets = new [] { 
                new Budget() {
                    ReceiptNumber = 111111,
                    CreatedUtc = new DateTime(2010, 6, 1, 9, 17, 0, DateTimeKind.Utc),
                    Interval = context.Intervals.GetByAbbreviation("2w"),
                    Entries = {
                        new Entry {
                            Amount = 800,
                            EntryType = context.EntryTypes.GetByCategoryAndName("Income", "Your take-home pay"),
                            Interval = context.Intervals.GetByAbbreviation("w"),
                        },
                        new Entry {
                            Amount = 400,
                            EntryType = context.EntryTypes.GetByCategoryAndName("Income", "Other"),
                            Interval = context.Intervals.GetByAbbreviation("m"),
                        },
                        new Entry {
                            Amount = 360,
                            EntryType = context.EntryTypes.GetByCategoryAndName("Financial Commitments", "Car loan repayments"),
                            Interval = context.Intervals.GetByAbbreviation("2w"),
                        },
                        new Entry {
                            Amount = 25,
                            EntryType = context.EntryTypes.GetByCategoryAndName("Financial Commitments", "Credit card interest"),
                            Interval = context.Intervals.GetByAbbreviation("m"),
                        },
                        new Entry {
                            Amount = 1000,
                            EntryType = context.EntryTypes.GetByCategoryAndName("Financial Commitments", "Savings"),
                            Interval = context.Intervals.GetByAbbreviation("m"),
                        },
                        new Entry {
                            Amount = 60,
                            EntryType = context.EntryTypes.GetByCategoryAndName("Financial Commitments", "Donations / charity"),
                            Interval = context.Intervals.GetByAbbreviation("m"),
                        },
                        new Entry {
                            Amount = 50,
                            EntryType = context.EntryTypes.GetByCategoryAndName("Financial Commitments", "Pocket money"),
                            Interval = context.Intervals.GetByAbbreviation("w"),
                        },
                        new Entry {
                            Amount = 1000,
                            EntryType = context.EntryTypes.GetByCategoryAndName("Home", "Home and contents insurance"),
                            Interval = context.Intervals.GetByAbbreviation("y"),
                        },
                        new Entry {
                            Amount = 1500,
                            EntryType = context.EntryTypes.GetByCategoryAndName("Home", "New furniture / appliances"),
                            Interval = context.Intervals.GetByAbbreviation("y"),
                        },
                        new Entry {
                            Amount = 300,
                            EntryType = context.EntryTypes.GetByCategoryAndName("Utilities", "Electricity"),
                            Interval = context.Intervals.GetByAbbreviation("2m"),
                        },
                        new Entry {
                            Amount = 30,
                            EntryType = context.EntryTypes.GetByCategoryAndName("Utilities", "Water"),
                            Interval = context.Intervals.GetByAbbreviation("m"),
                        },
                        new Entry {
                            Amount = 45,
                            EntryType = context.EntryTypes.GetByCategoryAndName("Utilities", "Internet"),
                            Interval = context.Intervals.GetByAbbreviation("m"),
                        },
                        new Entry {
                            Amount = 124,
                            EntryType = context.EntryTypes.GetByCategoryAndName("Utilities", "Mobile phone(s)"),
                            Interval = context.Intervals.GetByAbbreviation("m"),
                        },
                        new Entry {
                            Amount = 200,
                            EntryType = context.EntryTypes.GetByCategoryAndName("Health", "Private health insurance"),
                            Interval = context.Intervals.GetByAbbreviation("m"),
                        },
                        new Entry {
                            Amount = 160,
                            EntryType = context.EntryTypes.GetByCategoryAndName("Health", "Medicines / pharmacy"),
                            Interval = context.Intervals.GetByAbbreviation("2w"),
                        },
                        new Entry {
                            Amount = 20,
                            EntryType = context.EntryTypes.GetByCategoryAndName("Health", "Life insurance"),
                            Interval = context.Intervals.GetByAbbreviation("m"),
                        },
                        new Entry {
                            Amount = 200,
                            EntryType = context.EntryTypes.GetByCategoryAndName("Shopping", "Supermarket"),
                            Interval = context.Intervals.GetByAbbreviation("2w"),
                        },
                        new Entry {
                            Amount = 50,
                            EntryType = context.EntryTypes.GetByCategoryAndName("Shopping", "Baby products"),
                            Interval = context.Intervals.GetByAbbreviation("w"),
                        },
                        new Entry {
                            Amount = 250,
                            EntryType = context.EntryTypes.GetByCategoryAndName("Shopping", "Clothing / shoes"),
                            Interval = context.Intervals.GetByAbbreviation("3m"),
                        },
                        new Entry {
                            Amount = 200,
                            EntryType = context.EntryTypes.GetByCategoryAndName("Shopping", "Hairdresser"),
                            Interval = context.Intervals.GetByAbbreviation("6m"),
                        },
                        new Entry {
                            Amount = 50,
                            EntryType = context.EntryTypes.GetByCategoryAndName("Shopping", "Gifts and other"),
                            Interval = context.Intervals.GetByAbbreviation("2m"),
                        },
                        new Entry {
                            Amount = 50,
                            EntryType = context.EntryTypes.GetByCategoryAndName("Shopping", "Other food and grocery"),
                            Interval = context.Intervals.GetByAbbreviation("w"),
                        },
                        new Entry {
                            Amount = 800,
                            EntryType = context.EntryTypes.GetByCategoryAndName("Transport", "Car insurance"),
                            Interval = context.Intervals.GetByAbbreviation("y"),
                        },
                        new Entry {
                            Amount = 250,
                            EntryType = context.EntryTypes.GetByCategoryAndName("Transport", "Car maintenance"),
                            Interval = context.Intervals.GetByAbbreviation("6m"),
                        },
                        new Entry {
                            Amount = 500,
                            EntryType = context.EntryTypes.GetByCategoryAndName("Transport", "Car rego / licence"),
                            Interval = context.Intervals.GetByAbbreviation("y"),
                        },
                        new Entry {
                            Amount = 50,
                            EntryType = context.EntryTypes.GetByCategoryAndName("Transport", "Petrol"),
                            Interval = context.Intervals.GetByAbbreviation("w"),
                        },
                        new Entry {
                            Amount = 20,
                            EntryType = context.EntryTypes.GetByCategoryAndName("Transport", "Road tolls / parking"),
                            Interval = context.Intervals.GetByAbbreviation("m"),
                        },
                        new Entry {
                            Amount = 200,
                            EntryType = context.EntryTypes.GetByCategoryAndName("Entertainment", "Bars / clubs"),
                            Interval = context.Intervals.GetByAbbreviation("3m"),
                        },
                        new Entry {
                            Amount = 50,
                            EntryType = context.EntryTypes.GetByCategoryAndName("Entertainment", "Other alcohol"),
                            Interval = context.Intervals.GetByAbbreviation("2w"),
                        },
                        new Entry {
                            Amount = 50,
                            EntryType = context.EntryTypes.GetByCategoryAndName("Entertainment", "Movies / music"),
                            Interval = context.Intervals.GetByAbbreviation("m"),
                        },
                        new Entry {
                            Amount = 25,
                            EntryType = context.EntryTypes.GetByCategoryAndName("Entertainment", "Hobbies"),
                            Interval = context.Intervals.GetByAbbreviation("m"),
                        },
                        new Entry {
                            Amount = 15,
                            EntryType = context.EntryTypes.GetByCategoryAndName("Entertainment", "Newspaper / magazines"),
                            Interval = context.Intervals.GetByAbbreviation("m"),
                        },
                        new Entry {
                            Amount = 50,
                            EntryType = context.EntryTypes.GetByCategoryAndName("Entertainment", "Celebrations"),
                            Interval = context.Intervals.GetByAbbreviation("m"),
                        },
                        new Entry {
                            Amount = 150,
                            EntryType = context.EntryTypes.GetByCategoryAndName("Eating out", "Restaurants"),
                            Interval = context.Intervals.GetByAbbreviation("2m"),
                        },
                        new Entry {
                            Amount = 100,
                            EntryType = context.EntryTypes.GetByCategoryAndName("Eating out", "Takeaway / snacks"),
                            Interval = context.Intervals.GetByAbbreviation("w"),
                        },
                        new Entry {
                            Amount = 25,
                            EntryType = context.EntryTypes.GetByCategoryAndName("Eating out", "Coffee / tea"),
                            Interval = context.Intervals.GetByAbbreviation("w"),
                        },
                    },
                },
                new Budget() {
                    ReceiptNumber = 222222,
                    CreatedUtc = new DateTime(2010, 8, 3, 9, 19, 0, DateTimeKind.Utc),
                    Interval = context.Intervals.GetByAbbreviation("m"),
                },
                new Budget() {
                    ReceiptNumber = 333333,
                    CreatedUtc = new DateTime(2010, 11, 17, 11, 57, 0, DateTimeKind.Utc),
                    Interval = context.Intervals.GetByAbbreviation("2w"),
                },
                new Budget() {
                    ReceiptNumber = 444444,
                    CreatedUtc = new DateTime(2010, 12, 23, 12, 35, 0, DateTimeKind.Utc),
                    Interval = context.Intervals.GetByAbbreviation("w"),
                },
                new Budget() {
                    ReceiptNumber = 555555,
                    CreatedUtc = new DateTime(2010, 8, 30, 6, 42, 0, DateTimeKind.Utc),
                    Interval = context.Intervals.GetByAbbreviation("y"),
                },
            };

            foreach (var i in budgets)
                context.Budgets.Add(i);

            context.SaveChanges();
        }

    }}